package com.jintian.smart.kernel.security.provider;

import com.jintian.smart.base.api.security.provider.ISecurityPasswordProvider;
import com.jintian.smart.kernel.core.domain.RequestUser;
import com.jintian.smart.kernel.core.domain.ResponseDTO;
import com.jintian.smart.kernel.security.service.SecurityPasswordService;
import jakarta.annotation.Resource;
import org.apache.dubbo.config.annotation.DubboService;

@DubboService(timeout = 6000)
public class SecurityPasswordProvider implements ISecurityPasswordProvider {
    @Resource
    private SecurityPasswordService securityPasswordService;

    /**
     * 校验密码是否匹配
     */
    @Override
    public Boolean matchesPwd(String password, String encodedPassword) {
        return securityPasswordService.matchesPwd(password, encodedPassword);
    }

    /**
     * 检查是否需要修改密码
     */
    @Override
    public boolean checkNeedChangePassword(Integer userType, Long userId) {
        return securityPasswordService.checkNeedChangePassword(userType, userId);
    }

    /**
     * 随机生成密码
     */
    @Override
    public String randomPassword() {
        return securityPasswordService.randomPassword();
    }

    /**
     * 获取 加密后 的密码
     */
    @Override
    public String getEncryptPwd(String password) {
        return securityPasswordService.getEncryptPwd(password);
    }

    /**
     * 校验密码复杂度
     */
    @Override
    public ResponseDTO<String> validatePasswordComplexity(String password) {
        return securityPasswordService.validatePasswordComplexity(password);
    }

    /**
     * 校验密码重复次数
     */
    @Override
    public ResponseDTO<String> validatePasswordRepeatTimes(RequestUser requestUser, String newPassword) {
        return securityPasswordService.validatePasswordRepeatTimes(requestUser, newPassword);
    }

    /**
     * 保存修改密码
     */
    @Override
    public void saveUserChangePasswordLog(RequestUser requestUser, String newPassword, String oldPassword) {
        securityPasswordService.saveUserChangePasswordLog(requestUser, newPassword, oldPassword);
    }
}
